<%@ page contentType="text/html; charset=utf-8"%>
<%@ include file="/global/jsp-header.jsp"%>
<!DOCTYPE HTML>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html">
		<title>新增员工</title>
		<%@ include file="/global/html-header.jsp"%>
		<script>
	$(function() {
		$('.myform').idealforms();
		common.validator("workerform");
		//添加员工
		$("#workerform").submit(function(){
			$("#workerId").removeAttr("disabled");
			var param=$(this).serialize();
			var canSubmit=common.checkBlankValue(param,new Array("worker.workerId","worker.workerName","worker.password","worker.rank"
					,"worker.sex","worker.isDisabled","worker.trueName","worker.email","worker.mobile"));
			if(canSubmit){
				$.ajax({   
	        		type: "POST",  
	        		url: "${action }",  
	        		data: param, 
	        		success: function(msg){    
		        		window.parent.closeDialog();
		        		var alertMsg="";
	        			<c:if test="${addOperater}">
		        			if(msg=="success"){
	            				alertMsg="员工添加成功！";
	            				$(window.parent.document).find("#myform").submit();
	            			}else if(msg=="exists"){
	            				alertMsg="员工ID已存在！";
	            			}else{
	            				alertMsg="员工添加失败！";
	            			}
	        			</c:if>
	        			<c:if test="${updateOperater}">
		        			if(msg=="success"){
    	                    	alertMsg="员工更新成功！";
    	                    	$(window.parent.document).find("#myform").submit();
	            			}else if(msg=="nochange"){
	            				alertMsg="员工属性没有改变！";
	            			}else{
	            				alertMsg="员工更新失败！";
	            			}
        				</c:if>
        				window.parent.editWorkerTip(alertMsg);
	        		} 
	        	});
			}
			return false;
		});
	});
</script>
		<style>
			.ideal-form .ideal-wrap{clear: none;}
		</style>
	</head>
	<body>
		<form action="${action }" name="workerform" class="myform"
			id="workerform" method="post">
		<div class="leftDiv m25">
			<div>
				<label class="required">
					员工编号:
				</label>
				<input type="text" size="40" id="workerId" name="worker.workerId" class="{required:true,digits:true,messages:{required:'请输入员工编号'}}" ${updateOperater ? 'disabled=true':''} value="${worker.workerId }"/>
			</div>
			<div>
				<label class="required">
					员工名称:
				</label>
				<input type="text" size="40" name="worker.workerName" class="{required:true,messages:{required:'请输入员工名称'}}" value="${worker.workerName }"/>
			</div>
			<div>
				<label class="required">
					员工密码:
				</label>
				<input type="password" size="40" name="worker.password" class="{required:true,messages:{required:'请输入员工密码'}}" value="${worker.password }"/>
			</div>
			<div>
				<label class="required">
					员工职能:
				</label>
				<input type="text" size="40" name="worker.rank"
					class="{required:true,digits:true,messages:{required:'请输入员工职能'}}" value="${worker.rank }" />
			</div>
			<div>
				<label>
					&nbsp;
				</label>
				<input type="submit" value="${btnKeyWord }" />
			</div>
		</div>
		<div>
			<div>
				<label class="required">性别:</label>
				<select name="worker.sex" class="{required:true,messages:{required:'请选择员工性别'}}">
					<option value="">请选择</option>
					<option value="1" ${worker.sex eq 1 ? 'selected':'' }>男</option>
					<option value="0" ${worker.sex eq 0 ? 'selected':'' }>女</option>
				</select>
			</div>
			<div>
				<label class="required">是否可用:</label>
				<select name="worker.isDisabled" class="{required:true,messages:{required:'请选择员工是否可用'}}">
					<option value="">请选择</option>
					<option value="1" ${worker.isDisabled eq 1 ? 'selected':'' }>可用</option>
					<option value="0" ${worker.isDisabled eq 0 ? 'selected':'' }>不可用</option>
				</select>
			</div>
			<div>
				<label class="required">
					真名:
				</label>
				<input type="text" size="40" name="worker.trueName"
					class="{required:true,messages:{required:'请输入员工真名'}}" value="${worker.trueName }" />
			</div>
			<div>
				<label class="required">
					邮箱:
				</label>
				<input type="text" size="40" name="worker.email"
					class="{required:true,email:true,messages:{required:'请输入员工邮箱'}}" value="${worker.email }" />
			</div>
			<div>
				<label class="required">
					手机号码:
				</label>
				<input type="text" size="40" name="worker.mobile"
					class="{required:true,messages:{required:'请输入员工职能'}}" value="${worker.mobile }" />
			</div>
			<div>
				<label class="required">所属组别:</label>
				<c:forEach items="${groups }" var="item">
					<c:forEach items="${mygroups }" var="mygroupId">
						 <c:if test="${item.groupId eq mygroupId }">
						 	<c:set var="groupChecked" value="${true}"></c:set>
						 </c:if>
					</c:forEach>
					<label><input type="checkbox" name="groupIds" value="${item.groupId }" ${groupChecked ? "checked" : "" } />${item.groupName }</label>
					<c:set var="groupChecked" value="${false}"></c:set>
				</c:forEach>
			</div>
		</div>
	</form>
	</body>
</html>